<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<style>
			html {
				opacity: 0;
				width: 0px;
				height: 0px;
				overflow: hidden;
			}
		</style>
		<!-- <script src="./index.js" =></script> -->
	</head>
	<body>
		<script>
			document.addEventListener('plusready', function() {
				(function() {
					plus.downloader.createDownload("./index2.js", {}, function(d, status) {
						console.log(1)
					})


					plus.io.resolveLocalFileSystemURL(plus.webview.currentWebview().js, function(entry) {
						entry.file(function(file) {
							reader = new plus.io.FileReader();
							reader.onloadend = function(fileData) {
								let _str = fileData.target.result.replace("export default",
									"var all =")
								var _script = document.createElement("script");
								_script.innerHTML = _str;
								document.querySelectorAll("head")[0].appendChild(_script);
								let img = new Image();

								plus.io.resolveLocalFileSystemURL(plus.webview.currentWebview()
									.src,
									function(entry) {
										entry.file(function(file) {
											reader = new plus.io.FileReader();
											reader.onloadend = function(fileData) {
												img.src = fileData.target.result;
											};
											reader.readAsDataURL(file);
										});
									},
									function() {
										img.src = plus.webview.currentWebview().src;
									});
								img.onload = function() {
									captureImage(img)
								};
							};
							reader.readAsText(file);
						});
					}, function() {

					});
					var captureImage = function(img) {
						var canvas = document.createElement("canvas");
						canvas.width = img.width;
						canvas.height = img.height;
						let ctx = canvas.getContext('2d');
						ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
						let canvasData = ctx.getImageData(0, 0, canvas.width, canvas.height);
						ctx.putImageData(all[plus.webview.currentWebview().type](canvasData), 0, 0)
						let src = canvas.toDataURL("image/png");
						plus.storage.setItem(plus.webview.currentWebview().name, src);
					};

				})();
			}, false);
		</script>
	</body>
</html>